# -*- coding: utf-8 -*-
# base.models

from google.appengine.ext import db
from kay.auth.models import GoogleUser
import kay.db

class User(GoogleUser):
  pass

def delete_deck(deck):
  for card in Card.all().ancestor(deck):
    card.delete()
  deck.delete_self()
  
class Deck(db.Model):
  owner = kay.db.OwnerProperty()
  name = db.StringProperty(required=True)
  description = db.TextProperty()
  created = db.DateTimeProperty(auto_now_add=True)
  modified = db.DateTimeProperty(auto_now=True)

  def __unicode__(self):
    return self.name

  def delete(self):
    db.run_in_transaction(delete_deck, self)

  def delete_self(self):
    super(Deck, self).delete()

class Card(db.Model):
  owner = kay.db.OwnerProperty()
  word = db.StringProperty()
  definition = db.StringProperty(multiline=True)
  example = db.StringProperty(multiline=True)
  created = db.DateTimeProperty(auto_now_add=True)
  modified = db.DateTimeProperty(auto_now=True)
  # I should add some statistical information later.

  def __unicode__(self):
    return self.word
